package com.itheima.advice;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

@Slf4j
//@Component
//@Aspect
public class DemoAdvice {
    @Pointcut("execution(* com.itheima.service.impl.*.*(..))")
    public void pt(){}

    @Before("pt()")
    public void before(JoinPoint joinPoint) {
        log.info("执行了before方法");
    }

    @After("pt()")  // 有没有异常都执行
    public void after(JoinPoint joinPoint) {
        log.info("执行了after方法");
    }

    @AfterReturning("pt()")  // 没异常才执行
    public void afterReturning(JoinPoint joinPoint) {
        log.info("执行了afterReturning方法");
    }

    @AfterThrowing("pt()")  // 有异常再执行
    public void afterThrowing(JoinPoint joinPoint) {
        log.info("执行了afterThrowing方法");
    }
}
